library Revive requires Dto


struct Revive
    Unit m_ud

    timer m_timer
    real m_reviveX
    real m_reviveY
    real m_brithX
    real m_brithY
    boolean m_isEnable

    private static thistype array s_data

    static method get takes Unit ud returns thistype
        return s_data[integer(ud)]
    endmethod

    static method create takes Unit ud returns thistype
        local thistype this = thistype.get(ud)
        if this > 0 then
            return this
        endif
        set this = thistype.allocate()
        //变量初始化
        set this.m_ud = ud
        set this.m_timer = null
        set this.m_reviveX = 0.0
        set this.m_reviveY = 0.0
        set this.m_brithX = 0
        set this.m_brithY = 0
        set this.m_isEnable = true

        set s_data[integer(ud)] = this
        return this
    endmethod

    method destroy takes nothing returns nothing
        call ReleaseTimer(this.m_timer)
        set this.m_timer = null
        set s_data[integer(this.m_ud)] = 0
        call this.deallocate()
    endmethod

    method getTimer takes nothing returns timer
        if this.m_timer == null then
            set this.m_timer = NewTimer()
            call SetTimerData(this.m_timer, this)
        endif
        return this.m_timer
    endmethod

    method setReviveXY takes real x, real y returns nothing
        set this.m_reviveX = x
        set this.m_reviveY = y
    endmethod

    method setBrithXY takes real x, real y returns nothing
        set this.m_brithX = x
        set this.m_brithY = y
    endmethod

    private static method anon__0 takes nothing returns nothing
        local Dto dto = GetTimerData(GetExpiredTimer())
        local thistype revive = dto.m_data
        set revive.m_isEnable = true
        call dto.destroy()
    endmethod

    method delayEnable takes real timeout returns nothing
        local Dto dto = Dto.create()
        set dto.m_data = this
        call TimerStart(dto.getTimer(), timeout, false, function thistype.anon__0)
    endmethod
endstruct

endlibrary
